//
//  ZCRankingDeatailView.m
//  zctx
//
//  Created by apple on 16/2/26.
//  Copyright © 2016年 sanliang. All rights reserved.
//

#import "ZCRankingDeatailView.h"


@implementation ZCRankingDeatailView

-(id)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor colorWithHexString:@"#F1FBFE"];
        [self addSubViewOther:nil];
    }
    return self;
}

-(id)initWithFrame:(CGRect)frame andDetail:(ZCRankingListModelContent *)randmodel{
    if (self = [super initWithFrame:frame]) {

        self.backgroundColor = [UIColor colorWithHexString:@"#F1FBFE"];
        [self addSubViewOther:randmodel];
    }
    return self;
}

-(void)addSubViewOther:(ZCRankingListModelContent *)randModel{
    
    UIView *conView = [[UIView alloc]init];
    conView.backgroundColor = [UIColor colorWithHexString:@"#8CDFFE"];
    [self addSubview:conView];
    [conView makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.top).with.offset(18);
        make.centerX.equalTo(self.centerX).with.offset(0);
        make.width.mas_equalTo(SCREEN_WIDTH*0.926);
        make.height.mas_equalTo(SCREEN_WIDTH*1.12);
    }];
    
    // 0.56 - 360  0.75 - 500
    
    UILabel *numLable = [[UILabel alloc]initWithFrame:CGRectZero];
    [conView addSubview:numLable];
    numLable.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    numLable.text = [NSString stringWithFormat:@"共计%@票",randModel.voteNum];
    numLable.textAlignment = NSTextAlignmentRight;
    numLable.font = [UIFont systemFontOfSize:15];
    [numLable makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(conView.top).with.offset(15);
        make.right.equalTo(conView.right).with.offset(-20);
        make.height.mas_equalTo(@21);
        make.width.mas_equalTo(@100);
    }];
    
    UILabel *nameLable = [[UILabel alloc]initWithFrame:CGRectZero];
    [conView addSubview:nameLable];
    nameLable.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    nameLable.text = [NSString stringWithFormat:@"%@ %@号",randModel.vote_name,randModel.contentIdentifier];
    nameLable.font = [UIFont systemFontOfSize:15];
    [nameLable makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(conView.top).with.offset(15);
        make.left.equalTo(conView.left).with.offset(20);
        make.right.equalTo(numLable.left).with.offset(20);
        make.height.mas_equalTo(@21);
    }];
    
    UILabel *contentLable = [[UILabel alloc]initWithFrame:CGRectZero];
    [conView addSubview:contentLable];
    contentLable.textColor = [UIColor colorWithHexString:@"#FFFFFF"];
    contentLable.text = randModel.slogan;
    contentLable.font = [UIFont systemFontOfSize:15];
    [contentLable makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameLable.bottom).with.offset(5);
        make.left.equalTo(conView.left).with.offset(20);
        make.right.equalTo(conView.right).with.offset(-20);
        make.height.mas_equalTo(@21);
    }];
    
    UIImageView *imgView = [[UIImageView alloc]init];
    [conView addSubview:imgView];
    [imgView makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(conView.top).with.offset(75);
        make.centerX.equalTo(conView.centerX).with.offset(0);
        make.right.equalTo(conView.right).with.offset(-20);
        make.height.equalTo(imgView.width).with.offset(0);
    }];
    NSURL *url =[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",[NetworkManager strURLBasic],randModel.thumb]];
    NSLog(@"url = %@",url);
    [imgView sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placehold_involved"]];
    
    UIButton *shareButton = [[UIButton alloc]initWithFrame:CGRectZero];
    [self addSubview:shareButton];
    [shareButton makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.centerX).with.offset(0);
        make.top.equalTo(conView.bottom).with.offset(33);
        make.height.mas_equalTo(@40);
        make.width.mas_equalTo(@250);
    }];
    shareButton.layer.cornerRadius = 20;
    shareButton.titleLabel.font = [UIFont boldSystemFontOfSize:16];
    [shareButton setTitle:@"分享" forState:UIControlStateNormal];
    [shareButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    shareButton.backgroundColor = [UIColor colorWithHexString:@"#FFBE3C"];
    [shareButton addTarget:self action:@selector(showShareView) forControlEvents:UIControlEventTouchUpInside];
}

#pragma mark 分享
-(void)showShareView{
    NSLog(@"分享");
    self.shareClick();
}

@end
